package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.product.CategoryBrandVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author LT
 * @create 2024-03-17-16:55
 */
@RestController
@RequestMapping("/admin/product/categoryBrand")
@Tag(name = "分类品牌管理模块")
public class CategoryBrandController {

    @Resource
    CategoryBrandService categoryBrandService;

    @GetMapping("/list/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                       CategoryBrand categoryBrand){
        PageInfo<CategoryBrandVo> pageInfo = categoryBrandService.list(pageNum,pageSize,categoryBrand);
        return Result.ok(pageInfo);
    }

    @PostMapping("/save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.ok();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        categoryBrandService.delete(Arrays.asList(id));
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id){
        CategoryBrand categoryBrand = categoryBrandService.getById(id);
        return Result.ok(categoryBrand);
    }

    @PutMapping("/update")
    public Result update(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.update(categoryBrand);
        return Result.ok();
    }

    @GetMapping("/getBycategoryId/{categoryId}")
    public Result GetBrandByCategoryId(@PathVariable("categoryId")Long categoryId){
        List<Brand> brand = categoryBrandService.GetBrandByCategoryId(categoryId);
        return Result.ok(brand);
    }
}
